package com.doitedu;

import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.List;

/**
 * @Date 2021/12/10
 * @Created by HANGGE
 * @Description
 * 获取指定节点下 子节点和子节点的值
 */
public class C02_Demo02 {
    public static void main(String[] args) throws Exception {
        ZooKeeper zk = new ZooKeeper("linux01:2181,linux02:2181,linux03:2181", 2000, null);
        // 获取指定路径下的子节点
        List<String> children = zk.getChildren("/", null);
        // 遍历
        for (String child : children) {
            // 打印节点的名字   注意:没有/
            // 获取每个节点的值
            byte[] data = zk.getData("/" + child, null, null);
            System.out.println("/"+child+"   值是:  "+new String((data)));
        }

        zk.close();
    }
}
